package com.liehacker.android.etcs;

import java.net.InetAddress;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.liehacker.android.R;
import com.liehacker.android.ontop.LiehackerSuperActivity;

public class GetIPfromDns extends LiehackerSuperActivity{
	
	Button _btnEncrypt;
	Button _btnDecrypt;
	EditText _edtText;
	TextView _txtView;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.c03_edittext);
			
		_edtText = (EditText)findViewById(R.id.c03_edittext);
		_txtView = (TextView)findViewById(R.id.c03_result_text);
		
		_edtText.setText("m.tving.com");
		
		_btnEncrypt = (Button)findViewById(R.id.c03_encrypt_button);
		_btnEncrypt.setText("변환하기");
		
		_btnEncrypt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					GetIPfromDns.this.getIPfromDns();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		});
		
		_btnDecrypt = (Button)findViewById(R.id.c03_decrypt_button);
		_btnDecrypt.setVisibility(View.GONE);
		
		
		
	}
	
	public void getIPfromDns(){
		try {		
			
            String host = this._edtText.getText().toString();
            InetAddress addr = InetAddress.getByName(host);
            
            Log.i("liehacker", "host : " + addr.getAddress().toString() + "2 : " + addr.getCanonicalHostName().toString() + " 3: " + addr.getHostAddress().toString() + " 4: " + addr.getHostName().toString());
            this._txtView.setText( addr.getCanonicalHostName().toString() );
            
		} catch (Exception e) {
		    Log.e("error", e.getMessage().toString());
		}
	}
}
